#include<stdio.h>
#include<math.h>

#include "headers/Vector3d.h"

Vector3d::Vector3d(){}
Vector3d::Vector3d(double _x,double _y,double _z){x=_x;y=_y;z=_z;}

bool Vector3d::scan(){
	return scanf("%lf%lf%lf",&x,&y,&z)==3;}

double Vector3d::mag2(){
	return x*x+y*y+z*z;	}

double Vector3d::mag(){
	return sqrt(mag2());	}

void Vector3d::norm(){
	double d = mag();
	if(d){x/=d;y/=d;z/=d;}
}

Vector3d Vector3d::unit(){
	Vector3d ret = *this;	ret.norm(); return ret;}

void Vector3d::show(){
	printf("[%.2lf, %.2lf, %.2lf]",x,y,z);}

void Vector3d::showln(){
	printf("[%.2lf, %.2lf, %.2lf]\n",x,y,z);}

Vector3d operator+(Vector3d a,Vector3d b){	return Vector3d(a.x+b.x, a.y+b.y, a.z+b.z);}
Vector3d operator-(Vector3d a){				return Vector3d (-a.x, -a.y, -a.z);}
Vector3d operator-(Vector3d a,Vector3d b){	return Vector3d(a.x-b.x, a.y-b.y, a.z-b.z);}
Vector3d operator*(Vector3d a,Vector3d b){	return CROSS(a,b);}
Vector3d operator*(double a,Vector3d b){	return Vector3d(a*b.x, a*b.y, a*b.z);}
Vector3d operator*(Vector3d b,double a){	return Vector3d(a*b.x, a*b.y, a*b.z);}
Vector3d operator/(Vector3d b,double a){	return Vector3d(b.x/a, b.y/a, b.z/a);}

double DOT(Vector3d a, Vector3d b){	return a.x*b.x + a.y*b.y + a.z*b.z;}
Vector3d CROSS(Vector3d a, Vector3d b){	return Vector3d( a.y*b.z - a.z*b.y , a.z*b.x - a.x*b.z , a.x*b.y - a.y*b.x );}
double BOX(Vector3d a, Vector3d b, Vector3d c){	return DOT(a, CROSS(b,c));}

double projectLength(Vector3d proj, Vector3d on){	on.norm();	return DOT(on, proj);}
Vector3d projectVector(Vector3d proj, Vector3d on){	on.norm();	return on * projectLength(proj, on);}

Vector3d rotateVector(Vector3d rotatee, Vector3d axis, double angle){
	angle = angle*PI/180.;
	axis.norm();
	Vector3d normal = (axis * rotatee).unit();
	Vector3d mid = (normal * axis).unit();
	double r = projectLength(rotatee, mid);
	return (r*mid*cos(angle) + r*normal*sin(angle) + projectVector(rotatee, axis));
}

//AS POINTS
double pointDistance(Vector3d p1,Vector3d p2){
	double distX = p1.x - p2.x;
	double distY = p1.y - p2.y;
	double distZ = p1.z - p2.z;
	return sqrt(distX*distX + distY*distY + distZ*distZ);
}


Vector3d I(1,0,0);
Vector3d J(0,1,0);
Vector3d K(0,0,1);
Vector3d Origin(0,0,0);
